package com.qf.service.impl;

import com.qf.dao.FlowerMapper;
import com.qf.pojo.entity.Goods;
import com.qf.pojo.resp.BaseResp;
import com.qf.pojo.vo.StoreInfoVo;
import com.qf.service.FruitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class FruitServiceImpl implements FruitService {
    @Autowired
    FlowerMapper flowerMapper;
    @Override
    public BaseResp findByFree(String freeName) {
        List<StoreInfoVo> allFlower = flowerMapper.findAllFlower(7);
        List<StoreInfoVo> list = new ArrayList<StoreInfoVo>();

        for (StoreInfoVo storeInfoVo : allFlower) {
            if (storeInfoVo.getStoreDiscount().equals(freeName)){
                list.add(storeInfoVo);
            }
        }

        if (list!=null){
            //System.out.println(list);
            return new BaseResp(200, "success", list);
        }

        return new BaseResp().ERROR();
    }

    @Override
    public BaseResp findFruit(int id) {
        Goods fruit = new Goods();
        Goods fruit1 = new Goods();
        if (id == 31) {
             fruit = flowerMapper.findFruit(144);
             fruit1 = flowerMapper.findFruit(145);
        }else if (id == 32) {
             fruit = flowerMapper.findFruit(146);
             fruit1 = flowerMapper.findFruit(147);
        }else if (id == 33 ){
             fruit = flowerMapper.findFruit(148);
             fruit1 = flowerMapper.findFruit(149);
        }
        List<Goods> list = new ArrayList<Goods>();
        list.add(fruit);
        list.add(fruit1);
        if (list!=null) {
            return new BaseResp(200, "success", list);
        }

        return new BaseResp().ERROR();
    }
}
